Reads a the number of bytes specified or throws IOException
Syntax
Visual Basic (Declaration) | |
---|
Public Overloads Shared Sub Read( _
ByVal io As Stream, _
ByVal bytes() As Byte _
) |
Parameters
- io
- bytes
Example
Library/Library.Test/TestIOStreamUtils.cs
C# | Copy Code |
---|
byte[] testdata = new byte[2048];
new Random().NextBytes(testdata);
byte[] copy = new byte[testdata.Length];
IOStream.Read(FragmentStream(testdata, 16), copy);
Assert.AreEqual(Convert.ToBase64String(testdata), Convert.ToBase64String(copy));
byte[] copyb = new byte[testdata.Length / 2];
using (Stream s = FragmentStream(testdata, 16))
{
IOStream.Read(s, copy, copy.Length - copyb.Length);
IOStream.Read(s, copyb);
}
Array.Copy(copyb, 0, copy, copy.Length - copyb.Length, copyb.Length);
Assert.AreEqual(Convert.ToBase64String(testdata), Convert.ToBase64String(copy));
copy = IOStream.Read(FragmentStream(testdata, 16), testdata.Length);
Assert.AreEqual(Convert.ToBase64String(testdata), Convert.ToBase64String(copy)); |
VB.NET | Copy Code |
---|
Dim testdata As Byte() = New Byte(2048) {}
New Random().NextBytes(testdata)
Dim copy As Byte() = New Byte(testdata.Length) {}
IOStream.Read(FragmentStream(testdata, 16), copy)
Assert.AreEqual(Convert.ToBase64String(testdata), Convert.ToBase64String(copy))
Dim copyb As Byte() = New Byte(testdata.Length / 2) {}
Using s As Stream = FragmentStream(testdata, 16)
IOStream.Read(s, copy, copy.Length - copyb.Length)
IOStream.Read(s, copyb)
End Using
Array.Copy(copyb, 0, copy, copy.Length - copyb.Length, copyb.Length)
Assert.AreEqual(Convert.ToBase64String(testdata), Convert.ToBase64String(copy))
copy = IOStream.Read(FragmentStream(testdata, 16), testdata.Length)
Assert.AreEqual(Convert.ToBase64String(testdata), Convert.ToBase64String(copy)) |
Requirements
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
See Also